#define _CRT_SECURE_NO_WARNINGS
class Solution {
public:
    bool check(int* hash1, int* hash2)
    {
        for (int i = 0; i < 26; i++)
        {
            if (hash1[i] != hash2[i])  return false;
        }
        return true;
    }
    vector<int> findAnagrams(string s, string p) {
        int hash1[26], hash2[26] = { 0 };
        for (auto ch : p)  hash2[ch - 'a']++;
        vector<int> ret;
        for (int left = 0, right = 0; right < s.size(); right++)
        {
            hash1[s[right] - 'a']++;
            if (right - left + 1 == p.size())
            {
                if (check(hash1, hash2))  ret.push_back(left);
                hash1[s[left] - 'a']--;
                left++;
            }
        }
        return ret;
    }
};

class Solution {
public:
    int subarraySum(vector<int>& nums, int k) {
        //0,1,2,3
        //0,1,3,6   6 - ? = 3;
        unordered_map<int, int> hash1;
        int sum = 0, ret = 0;
        hash1[0]++;
        for (auto e : nums)
        {
            sum += e;
            if (hash1.count(sum - k))
            {
                ret += hash1[sum - k];
            }
            hash1[sum]++;
        }
        return ret;
    }
};

class Solution {
public:
    int maxSubArray(vector<int>& nums) {
        int sum = 0, ret = INT_MIN;
        int tmp = 0;
        for (auto& e : nums)
        {
            sum += e;
            ret = max(ret, sum - tmp);
            tmp = min(sum, tmp);
        }
        return ret;
    }
};